const express = require('express');
const router = express.Router();
const OutboundController = require('../controllers/outboundController');

/**
 * @swagger
 * tags:
 *   name: Outbound
 *   description: 出库管理
 */

/**
 * @swagger
 * /api/outbound:
 *   get:
 *     summary: 获取所有出库单据
 *     tags: [Outbound]
 *     responses:
 *       200:
 *         description: 成功获取出库单据列表
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 data:
 *                   type: array
 *                   items:
 *                     $ref: '#/components/schemas/OutboundDocument'
 *       500:
 *         description: 服务器错误
 */
router.get('/', OutboundController.getAllOutboundDocuments);

/**
 * @swagger
 * /api/outbound/query:
 *   get:
 *     summary: 查询出库数据
 *     tags: [Outbound]
 *     parameters:
 *       - in: query
 *         name: materialName
 *         schema:
 *           type: string
 *         description: 物料名称
 *       - in: query
 *         name: materialCode
 *         schema:
 *           type: string
 *         description: 物料编码
 *       - in: query
 *         name: location
 *         schema:
 *           type: string
 *         description: 货位号
 *       - in: query
 *         name: aisle
 *         schema:
 *           type: string
 *         description: 巷道
 *       - in: query
 *         name: row
 *         schema:
 *           type: string
 *         description: 排
 *       - in: query
 *         name: column
 *         schema:
 *           type: string
 *         description: 列
 *       - in: query
 *         name: level
 *         schema:
 *           type: string
 *         description: 层
 *     responses:
 *       200:
 *         description: 成功获取查询结果
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 data:
 *                   type: array
 *                   items:
 *                     type: object
 *                     properties:
 *                       id:
 *                         type: integer
 *                       location:
 *                         type: string
 *                       pallet:
 *                         type: string
 *                       materialCode:
 *                         type: string
 *                       materialName:
 *                         type: string
 *                       specification:
 *                         type: string
 *                       unit:
 *                         type: string
 *                       quantity:
 *                         type: integer
 *       500:
 *         description: 服务器错误
 */
router.get('/query', OutboundController.queryOutbound);

/**
 * @swagger
 * /api/outbound/{id}:
 *   get:
 *     summary: 根据ID获取出库单据
 *     tags: [Outbound]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 出库单据ID
 *     responses:
 *       200:
 *         description: 成功获取出库单据
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 data:
 *                   $ref: '#/components/schemas/OutboundDocument'
 *       404:
 *         description: 出库单据未找到
 *       500:
 *         description: 服务器错误
 */
router.get('/:id', OutboundController.getOutboundDocumentById);

/**
 * @swagger
 * /api/outbound:
 *   post:
 *     summary: 创建新出库单据
 *     tags: [Outbound]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - goods_id
 *               - customer
 *               - quantity
 *             properties:
 *               goods_id:
 *                 type: integer
 *                 description: 货物ID
 *               customer:
 *                 type: string
 *                 description: 客户
 *               quantity:
 *                 type: integer
 *                 description: 数量
 *               expected_pickup_date:
 *                 type: string
 *                 format: date
 *                 description: 预计提货日期
 *               actual_pickup_date:
 *                 type: string
 *                 format: date
 *                 description: 实际提货日期
 *               status:
 *                 type: string
 *                 description: 状态
 *               operator:
 *                 type: string
 *                 description: 操作员
 *               notes:
 *                 type: string
 *                 description: 备注
 *     responses:
 *       201:
 *         description: 出库单据创建成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 message:
 *                   type: string
 *                 data:
 *                   $ref: '#/components/schemas/OutboundDocument'
 *       400:
 *         description: 请求参数错误
 *       500:
 *         description: 服务器错误
 */
router.post('/', OutboundController.createOutboundDocument);

/**
 * @swagger
 * /api/outbound/{id}/status:
 *   put:
 *     summary: 更新出库单据状态
 *     tags: [Outbound]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 出库单据ID
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - status
 *             properties:
 *               status:
 *                 type: string
 *                 description: 状态
 *     responses:
 *       200:
 *         description: 出库单据状态更新成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 message:
 *                   type: string
 *       400:
 *         description: 请求参数错误
 *       404:
 *         description: 出库单据未找到
 *       500:
 *         description: 服务器错误
 */
router.put('/:id/status', OutboundController.updateOutboundDocumentStatus);

/**
 * @swagger
 * /api/outbound/{id}/cancel:
 *   put:
 *     summary: 取消出库单据
 *     tags: [Outbound]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 出库单据ID
 *     responses:
 *       200:
 *         description: 出库单据取消成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 message:
 *                   type: string
 *       404:
 *         description: 出库单据未找到
 *       500:
 *         description: 服务器错误
 */
router.put('/:id/cancel', OutboundController.cancelOutboundDocument);

module.exports = router;